import login from "./login"

const state = {
  mealInfo: [],
  //全部文件信息
  fileInfo: {},
  // 未完成
  accomplish: {},
  //预览合同
  previewInfo: {},
  //pdf转图片
  pdfImage: [],
  //文件详情
  operatorInfo:{},
  //过程存储
  courseInfo:{},

}
const mutations = {
  GETMEALINFO(state, mealInfo) {
    state.mealInfo = mealInfo
  },
  GETCONTRACTINFO(state, fileInfo) {
    state.fileInfo = fileInfo
  },
  GETACCOMPLISH(state, accomplish) {
    state.accomplish = accomplish
  },
  GETPREVIEWFILEINFO(state, previewInfo) {
    state.previewInfo = previewInfo
  },
  GETPDFIMAGE(state, pdfImage) {
    state.pdfImage = pdfImage
  },
  GETOPERATORINFO(state, operatorInfo) {
    state.operatorInfo = operatorInfo
  },
   GETCIURSEINFO(state, courseInfo) {
    state.courseInfo = courseInfo
  },
}
const actions = {
  //获取合同
  async getContractInfo({
    commit
  }) {
    let result = await uni.$http.get(`/app/v1/contract`)
    console.log('合同', result)
    if (result.data.code == 200) {
      commit('GETCONTRACTINFO', result.data.data)
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
  //搜索合同
  async getSearch({
    commit
  }, newV) {
    let data = {
      keyValue: newV,
    }

    console.log(data)
    let result = await uni.$http.get(`/app/v1/contract`, data)
    console.log('搜索', result)
    if (result.data.code == 200) {
      commit('GETCONTRACTINFO', result.data.data)
    }
  },
  //获取预览合同
  async getPreviewFileInfo({
    commit
  }) {
    let param = {
      type: 5
    }
    let result = await uni.$http.get(`/app/v1/contract/getFileDataList`, param)
    console.log('获取预览合同', result)
    if (result.data.code == 200) {
      commit('GETPREVIEWFILEINFO', result.data.data)
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
  //获取切图pdf照片
  async getPDFImage({
    commit
  }, param) {
    let result = await uni.$http.get('/app/v1/contract/getPdfDrawingImg', param)
    console.log('获取切图pdf照片', result)
    if (result.data.code == 200) {
      commit('GETPDFIMAGE', result.data.data)
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
  //添加签署方
  async addSignUserData({
    commit
  }, param) {
    console.log('添加签署方', param)
    let result = await uni.$http.get('/app/v1/contract/getSignUserData', param)
    console.log('添加签署方', result)
    if (result.data.code == 200) {
      //本地存储
      let signUserList=uni.getStorageSync('signUserList');
      signUserList.push(result.data.data)
      uni.setStorageSync('signUserList', signUserList);
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
  //发起签署
  async createContract({commit}, param) {
    console.log('发起签署参数', param)
    let result = await uni.$http.post('/app/fxqApi/createContract', param)
    console.log('发起签署', result)
    if (result.data.code == 200) {
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
  //签名设置
  async upSignature({commit}, param) {
    console.log('签名设置', param)
    let result = await uni.$http.post('/app/fxqApi/handleStamp', param)
    console.log('签名设置', result)
    if (result.data.code == 200) {
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
  //签约详情
  async getOperatorInfo({
    commit
  }, id) {
    console.log('签约详情参数', id)
    let result = await uni.$http.get(`/app/operatorInfo/getContractHandleLog?contractId=${id}`)
    console.log(result)
    if (result.data.code == 200) {
      commit('GETOPERATORINFO', result.data.data)
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
  //签约过程详情
  async getCourseInfo({
    commit
  }, id) {
    let result = await uni.$http.get(`/app/operator_info/query-contract-desc?contractId=${3}`)
    console.log(result)
    if (result.data.code == 200) {
      commit('GETCIURSEINFO', result.data.data)
      return 'ok'
    } else {
      return Promise.reject(new Error(result.data.msg));
    }
  },
}


//计算属性:在项目在中,为简化数据而生
const getters = {

}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
